<tpl var layoutBody={ />
<div data-identity="wxmp:menus" data-table="wxmp_menus">
	<div class="layui-breadcrumb">
		<a href="/manage/index.jspx">首页</a>
		<a href="javascript:;"><cite>菜单管理</cite></a>
	</div>
	<hr>
	<form class="layui-form layui-form-pane" lay-filter="mWxmpMenusSearchForm">
		<div class="layui-form-item layui-inline nobottom">
			<label class="layui-form-label width-auto">菜单标题</label>
			<div class="layui-input-inline">
				<input type="text" name="title" placeholder="请输入菜单标题" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-inline nobottom">
			<label class="layui-form-label width-auto">APPID</label>
			<div class="layui-input-inline">
				<input type="text" name="appid" placeholder="请输入APPID" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-inline nobottom">
			<button class="layui-btn" lay-submit lay-filter="mWxmpMenusSearchForm">查找</button>
			<a href="create.jspx" class="layui-btn layui-btn-primary">添加</a>
			<tpl if(isNotEmpty (appid!)){ />
			<button type="button" class="layui-btn layui-btn-normal" id="get_menus">获取菜单</button>
			<button type="button" class="layui-btn layui-btn-normal" id="get_menus_self">获取菜单(self)</button>
			<tpl } />
		</div>
	</form>
	<table class="layui-table" lay-data="{height: 'full-220', page: {hash: 'page'}, limit:30, loading:true, url:'list.json?_appid=${appid!}',id: 'mWxmpMenusTable'}" lay-filter="mWxmpMenusTableFilter">
		<thead>
			<tr>
				<th lay-data="{unresize:true,field:'id', align: 'center', width:60}">ID</th>
				<th lay-data="{unresize:true,field:'res_groupn'}">所属组</th>
				<th lay-data="{unresize:true,field:'uuid', width:300}">菜单编号</th>
				<th lay-data="{unresize:true,field:'wxname'}">公众号</th>
				<th lay-data="{unresize:true,field:'title'}">菜单标题</th>
				<th lay-data="{unresize:true,field:'menuid'}">菜单ID</th>
				<th lay-data="{unresize:true,field:'appid'}">APPID</th>
				<th lay-data="{unresize:true,field:'create_time', width:200}">创建时间</th>
				<th lay-data="{unresize:true,field:'update_time', width:200}">更新时间</th>
				<th lay-data="{unresize:true,fixed: 'right', width:180, align:'center', toolbar: '#toolbar-tpl'}"></th>
			</tr>
		</thead>
	</table>
</div>
<tpl }; />

<tpl var layoutScript={ />
<script type="text/javascript">
	layui.config({
		base: '${webCdn}/plugins/layui/modules/'
	}).extend({
		http: 'http/http.min',
		message: 'message/message.min',
		eventbus: 'eventbus/eventbus.min'
	}).use(['element', 'message', 'eventbus', 'table', 'form', 'http'], function () {
		// 搜索框表单提交事件
		layui.form.on('submit(mWxmpMenusSearchForm)', function (data) {
			layui.table.reload('mWxmpMenusTable', {
				where: data.field,
				page: {
					'curr': 1
				}
			});
			return false;
		});

		$('#get_menus').on('click', function () {
			layui.message.confirm('获取该菜单方案(不会进行覆盖)?', function (index) {
				layui.http.post('sycn.json?appid=${appid!}', function (res) {
					layui.message.success(res.message, () => obj.del());
				});
			});
		});

		$('#get_menus_self').on('click', function () {
			layui.message.confirm('获取该菜单方案(self:不会进行覆盖)?', function (index) {
				layui.http.post('sycn/base.json?appid=${appid!}', function (res) {
					layui.message.success(res.message, () => obj.del());
				});
			});
		});

		// 数据表格-工具栏-删除按钮点击事件
		layui.eventbus.table('mWxmpMenusTableFilter', 'del', function (obj) {
			layui.message.confirm('确定删除该菜单方案?', function (index) {
				layui.http.post('save.json?oper=delete&id=' + obj.data.id, function (res) {
					layui.message.success(res.message, () => obj.del());
				});
			});
		});

		// 数据表格-工具栏-推送按钮点击事件
		layui.eventbus.table('mWxmpMenusTableFilter', 'push', function (obj) {
			layui.message.confirm('确定推送该菜单方案?', function (index) {
				layui.http.post(`push.json?appid=\${obj.data.appid}&uuid=\${obj.data.uuid}`, function (res) {
					layui.message.success(res.message, () => obj.del());
				});
			});
		});
	});
</script>
<script type="text/html" id="toolbar-tpl">
	<div class="layui-btn-group">
		<a href="view.jspx?uuid={{d.uuid}}" class="layui-btn layui-btn-xs">查看</a>
		<a href="update.jspx?uuid={{d.uuid}}" class="layui-btn layui-btn-xs">编辑</a>
		<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="push">推送</button>
		<button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
	</div>
</script>
<tpl }; />
<tpl include( "../../tpl/layout.html" ,{identity: "wxmp:menus" ,layoutBody:layoutBody,layoutScript:layoutScript}){} />